home *** CD-ROM | disk | FTP | other *** search
- /*
- File: ShimSerialUtils.c
-
- Contains: Utility routines
-
- Version: xxx put version here xxx
-
- Copyright: © 1996-1998 by Apple Computer, Inc., all rights reserved.
-
-
- */
-
- #include "ShimSerialInternal.h"
-
- void *
- GetDeviceProperty( const RegEntryID * deviceEntry,
- const RegPropertyName * propertyName,
- RegPropertyValueSize * propertySize)
- {
- OSStatus status;
- void * propertyBuffer = NULL;
-
-
- SysDebugStr("\pGetDeviceProperty() entered !");
-
-
- status = RegistryPropertyGetSize(deviceEntry,propertyName,propertySize);
- if (status == noErr)
- {
- propertyBuffer = PoolAllocateResident(*propertySize,true);
- if (propertyBuffer)
- status = RegistryPropertyGet(deviceEntry,propertyName,propertyBuffer,propertySize);
- }
-
- if (status != noErr)
- propertyBuffer = NULL;
-
- return propertyBuffer;
- }
-
- void
- DisposeDeviceProperty(void * propertyToDispose)
- {
- SysDebugStr("\pDisposeDeviceProperty() entered !");
- if (propertyToDispose)
- PoolDeallocate(propertyToDispose);
- }
-
-
-
- /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- * DoOpenSession
- *
- * Process an OpenDriver request to the stub drivers.
- */
- OSStatus DoOpenSession(ParmBlkPtr pb)
- {
- OSStatus err;
- #pragma unused (pb)
-
-
- // only allow one open session
-
- if (gGlobals->openSession)
- return openErr;
-
- // reset internal indexes, buffers, etc.
-
- err = B_SetBuffer(gGlobals, nil, 0);
- if (err)
- return err;
-
- // since we've cleared the buffer to zero initially we have to explicitly
- // initialize the baudRate, otherwise B_SetBaudRate will do a zero divide
-
- gGlobals->baudRate = kMaxBaudRate; // <-- is this the right/reasonable value?
- // we can get the baud rate from the GET_CAPS function as well
- gGlobals->UARTCrystalSpeed = 3686400; // should get this from the device capabilities
- // gGlobals->UARTCrystalSpeed = 1843200; // should get this from the device capabilities
-
- // reset default values for other variables
-
- gGlobals->lenParStop = kLen8Bits + kParNone + kStop1Bit;
- gGlobals->xOnOffChar = 0;
- gGlobals->peChar = 0;
- gGlobals->peAltChar = 0;
-
- // reset handshake default values as per scc serial driver
-
- gGlobals->serShk.fXOn = 0;
- gGlobals->serShk.fCTS = 1;
- gGlobals->serShk.xOn = 0;
- gGlobals->serShk.xOff = 0;
- gGlobals->serShk.errs = parityErr | hwOverrunErr | framingErr;
- gGlobals->serShk.evts = 0;
- gGlobals->serShk.fInX = 0;
- gGlobals->serShk.fDTR = 1;
-
- // reset serial status record
-
- gGlobals->serStat.cumErrs = 0;
- gGlobals->serStat.xOffSent = 0;
- gGlobals->serStat.rdPend = 0;
- gGlobals->serStat.wrPend = 0;
- gGlobals->serStat.ctsHold = 0;
- gGlobals->serStat.xOffHold = 0;
-
-
-
- // now turn on modem interrupts
-
- B_EnableSerialDevice(gGlobals);
-
- // we now have an open session
-
- gGlobals->openSession = true;
-
-
- return noErr;
- }
-
-
-
-
-
- /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- * DoCloseSession
- *
- * Process an CloseDriver request to the stub drivers.
- */
- OSStatus DoCloseSession(ParmBlkPtr pb)
- {
- #pragma unused (pb)
-
-
- if (gGlobals && gGlobals->openSession)
- {
-
- // now turn off interrupts on the card
-
- B_DisableSerialDevice(gGlobals);
-
-
-
- // reset internal indexes, buffers, etc. - this
- // is important for vm to unhold memory on any
- // buffer the client may have requested earlier
-
- B_SetBuffer(gGlobals, nil, 0);
-
-
- // we no longer have an open session
-
- gGlobals->openSession = false;
- }
-
- return noErr;
- }
-
-